package com.jbm.core.client.remote;

import com.jbm.core.client.MainCallback;
import com.jbm.core.common.AccountCtrl;
import com.jbm.core.common.ConnectAgent;
import com.jbm.core.common.MainServer;
import com.jbm.core.iface.IAcross;
import com.jbm.core.iface.IP2P;

/**
 * Created by root on 17-2-28.
 */
public class RIP2P extends IP2P
{
	public RIP2P()
	{
	}

	public RIP2P(IAcross ia)
	{
		super(ia);
	}

	public IAcross ConnectP2P()
	{
		IP2P req = (IP2P)m_input;

		ConnectAgent ca = AccountCtrl.g_accountctrl.GetCA(req.m_fromer,req.m_msg);

		if ( ca == null )
			return new IAcross(404,"Not found CA");

		ca.ConnectP2P(false);

		return new IAcross(200,"OK");
	}

	public IAcross ArcossNAT()
	{
		return new IAcross(200,"OK");
	}

	public IAcross PushPoint ( )
	{
		IP2P p2p = (IP2P)m_input;

		MainCallback callback = MainServer.getG_server().getM_maincallback();

		if ( callback != null )
		{
			callback.NewText(p2p.m_fromer,p2p.m_msg,p2p.m_timestamp);
		}

		System.out.println("IP2P.PushPoint from:"+p2p.m_fromer+"msg:"+p2p.m_msg);

		return new IAcross(200,"PushOK");
	}

	public IAcross PushFile()
	{
		IP2P p2p = (IP2P)m_input;

		MainCallback callback = MainServer.getG_server().getM_maincallback();

		if ( callback != null )
		{
			callback.NewFile(p2p.m_fromer,p2p.m_file,p2p.m_timestamp);
		}

		p2p.cancelExcode();
		return p2p;
	}

	public IAcross CGPushPoint()
	{
		IP2P p2p = (IP2P)m_input;

		MainCallback callback = MainServer.getG_server().getM_maincallback();

		if ( callback != null )
		{
			callback.CGNewText(p2p.m_cg_id, p2p.m_fromer,p2p.m_msg,p2p.m_timestamp);
		}

		System.out.println("IP2P.PushPoint from:"+p2p.m_fromer+"msg:"+p2p.m_msg);

		return new IAcross(200,"CGPushOK");
	}

	public IAcross CGPushFile()
	{
		IP2P p2p = (IP2P)m_input;

		MainCallback callback = MainServer.getG_server().getM_maincallback();

		if ( callback != null )
		{
			callback.CGNewFile(p2p.m_cg_id, p2p.m_fromer,p2p.m_file,p2p.m_timestamp);
		}

		p2p.cancelExcode();
		return p2p;
	}
	public IAcross newOrder()
	{
      //neworder 新抢单给商家
      // pass抢单成功给刷手
      // refuse抢单不成功
		//cancelss 申请取消订单 给商家
		// confirmcancelss 取消申请确认 给刷手

		//cancelsj 商家申请取消订单 给刷手
		//confirmcancelsj 刷手取消申请确认 给商家
//dooverss 刷手申请做单完成  给商家

		//confirmdooverReject 拒绝做单完成申请 给刷手
		//confirmdoover  确认做单完成 给刷手  "userpay:100金米,deposit:300金米,mibao:20米宝,blance:0金米,ordercode:201251364411"
		//alloverss  刷手申请收菜完成  给商家

		//confirmalloverReject 拒绝收菜完成申请 给刷手
		//confirmallover  确认收菜完成 给刷手  "userpay:100金米,deposit:300金米,mibao:20米宝,blance:0金米,ordercode:201251364411"
		//iceout  申请解冻垫付款 给商家
		 // auditiceout 审核解冻垫付款 给刷手
		//cancelorder  取消订单完成 给商家 带钱  "userpay:100金米,deposit:300金米,mibao:2米宝";
		//arbirateApply  仲裁  给被仲裁方  "ordercode:201251364411"
		//recharge
		//cert 实名认证 msg:“passed:true,failed_reason:未通过原因”

		IP2P p2p = (IP2P)m_input;

		MainCallback callback = MainServer.getG_server().getM_maincallback();

		if ( callback != null )
		{
			callback.newOrder(p2p.order_id,p2p.task_id,p2p.m_fromer, p2p.type,p2p.m_msg, p2p.m_timestamp,p2p.msg_id);
		}

		p2p.cancelExcode();
		return p2p;
	}

}
